// 类
// 内容：
// 1. 定义类，初始化
// 2. 默认构造函数-完整
// 3. 默认构造函数-简写
// 4. 命名构造函数
// 5. 私有属性
import './lib.dart';

void main(){
  // === 1 ===
  Person p1 = new Person();
  p1.age = 12;
  p1.name = 'popo';
  p1.say();

  // === 2 ===
  Person2 p2 = new Person2('yellow', 23);
  p2.say();

  // === 3 ===
  Person3 p3 = new Person3('Tom', 10);
  print(p3.age);
  p3.say();

  // === 4 ===
  Person4 p4 = new Person4('Wenger', 60);
  print(p4._age); // 本文件私有化无效
  p4.say();

  // === 5 ===
  Person5 p5 = new Person5('viTa', 18);
  // p5._age; // error
  p5.say();
}

// === 1 ===
class Person {
  String? name;
  int? age;

  say(){
    print('$name is $age year old');
  }
}

// === 2 ===
class Person2 {
  Person2(String name, int age){
    this.name = name;
    this.age = age;
  }
  String? name;
  int? age;

  say(){
    print('$name is $age year old');
  }
}

// === 3 ===
class Person3 {
  Person3(this.name, this.age);

  String? name;
  int? age;

  say(){
    print('$name is $age year old');
  }
}

// === 4 ===
class Person4 {
  Person4(this._name, this._age);

  String? _name;
  int? _age;

  say(){
    print('$_name is $_age year old');
  }
}